Ext.define('Admin.view.announcement.AnnouncementViewController', {
    extend: 'Ext.app.ViewController',
    alias: 'controller.announcementViewController',
      
    
    openAddWindow: function() {
              var cfg = Ext.apply({
                xtype: 'announcementAddWindow',
                items: [Ext.apply({xtype: 'announcementAddForm'})]
    });
    var win = Ext.create(cfg);
    },
    submitAddForm:function(btn){
        var form = btn.up('form');
        form.getForm().submit({       
        url:'announcement/saveOrUpdate',
        //waitMsg: '正在上传，请耐心等待....',
        success: function(view, action){    
          Ext.Msg.alert('提示', action.result.msg,function(){
            btn.up('window').close();
            //form.getViewModel().getStore('employStore').reload();
             Ext.getCmp('announcementGridPanel').getStore().reload();
          });       
        },       
        failure: function(view, action){
          Ext.Msg.alert('提示', action.result.msg);
        }
      });

    },
    delete: function(view, recIndex, cellIndex, item, e, record) {
          Ext.MessageBox.confirm('提示', '确定要进行删除操作吗？数据将无法还原！',
            function(btn, text){
                  if(btn=='yes'){
                      Ext.Ajax.request({ 
                url : 'announcement/delete', 
                method : 'post', 
                params : { 
                  id :record.get('id')
                }, 
                success: function(response, options) {
                          var json = Ext.util.JSON.decode(response.responseText);
                        if(json.success){
                          Ext.Msg.alert('系统提示', json.msg, function() {
                                view.getStore().reload();
                            });
                      }else{
                         Ext.Msg.alert('系统提示', json.msg);
                      }
                      }
              });
                  }
              }
            , this);
    },
    deletes: function(btn) {
        var grid = btn.up('gridpanel');
    var selModel = grid.getSelectionModel();
        if (selModel.hasSelection()) {
            Ext.Msg.confirm("警告", "确定要删除吗？", function (button) {
                if (button == "yes") {
                    var rows = selModel.getSelection();
                    var selectIds = []; //要删除的id
                    Ext.each(rows, function (row) {
                        selectIds.push(row.data.id);
                    });
                    Ext.Ajax.request({ 
            url : 'announcement/deletes', 
            method : 'post', 
            params : { 
              //ids[] :selectIds
              ids :selectIds
            }, 
            success: function(response, options) {
                      var json = Ext.util.JSON.decode(response.responseText);
                    if(json.success){
                      Ext.Msg.alert('操作成功', json.msg, function() {
                            grid.getStore().reload();
                        });
                  }else{
                     Ext.Msg.alert('操作失败', json.msg);
                  }
                  }
          });

                }
            });
        }
        else {
            Ext.Msg.alert("错误", "没有任何行被选中，无法进行删除操作！");
        }
    } 
});